package jxtend.processor.eclipse.visitor.traverser;

import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;

@SuppressWarnings("restriction")
public class MethodDeclarationTraverser implements ASTNodeChildrenTraverser {

	@Override
	public boolean isApplicable(ASTNode node) {
		return (node instanceof MethodDeclaration);
	}

	@Override
	public void traverseChildren(ASTNode node, ASTVisitor visitor, BlockScope scope) {
		MethodDeclaration methodDeclaration = (MethodDeclaration) node;

		if (methodDeclaration.javadoc != null) {
			methodDeclaration.javadoc.traverse(visitor, methodDeclaration.scope);
		}
		if (methodDeclaration.annotations != null) {
			int annotationsLength = methodDeclaration.annotations.length;
			for (int i = 0; i < annotationsLength; i++)
				methodDeclaration.annotations[i].traverse(visitor, methodDeclaration.scope);
		}
		if (methodDeclaration.typeParameters != null) {
			int typeParametersLength = methodDeclaration.typeParameters.length;
			for (int i = 0; i < typeParametersLength; i++) {
				methodDeclaration.typeParameters[i].traverse(visitor, methodDeclaration.scope);
			}
		}
		if (methodDeclaration.returnType != null)
			methodDeclaration.returnType.traverse(visitor, methodDeclaration.scope);
		if (methodDeclaration.arguments != null) {
			int argumentLength = methodDeclaration.arguments.length;
			for (int i = 0; i < argumentLength; i++)
				methodDeclaration.arguments[i].traverse(visitor, methodDeclaration.scope);
		}
		if (methodDeclaration.thrownExceptions != null) {
			int thrownExceptionsLength = methodDeclaration.thrownExceptions.length;
			for (int i = 0; i < thrownExceptionsLength; i++)
				methodDeclaration.thrownExceptions[i].traverse(visitor, methodDeclaration.scope);
		}
		if (methodDeclaration.statements != null) {
			int statementsLength = methodDeclaration.statements.length;
			for (int i = 0; i < statementsLength; i++)
				methodDeclaration.statements[i].traverse(visitor, methodDeclaration.scope);
		}
	}

}
